Release 10.1A: OpenEdge Development:
Progress Dynamics Basic Development
Retrieving and formatting error messages with aferrortxt.i
The include file you use in a validation procedure of any kind to format a message to prepare it for return to the client is
aferrortxt.i. This include file has been designed to simplify and standardize the format of Progress Dynamics messages. The include file supports the unnamed arguments listed in Table 10–1.
Resulting message format
The whole purpose of
aferrortxt.iis to shield you from being concerned about the exact format of the various components of a formatted message. For informational purposes, this section explains the resulting format.The include file equates to a single string value of the formatted message with appropriate delimiters. The format conforms to that expected and used by ADM2, which is:
Additionally, the format adds on the following for extra information on where the error occurred:
The format of the message part conforms to that required by Progress Dynamics for reading of the error message from a message table in the database, which is:
This is a carat (^)-separated list starting with the message group, then the message code, then the program the message occurred in, then a pipe (|)-delimited list of optional insertion codes to replace in the found message text returned from the database table.
Where insertion codes exist in the message text, values must be passed into the appropriate include file argument as explained above. Note that arguments to the include file must be passed in as unquoted variable names or single-quoted literals (for example, 'text'). If a literal contains spaces, then it must be enclosed in double quotes, then single quotes (for example, “'text space'”). If double quotes are specified, these will be dropped automatically. If arguments need to be left blank, then a placeholder of '?' must be used if the argument is not the last item in the list. Only the first two arguments are mandatory.
An example of an include file for a standard Progress Dynamics message with no insertion codes is:
If the message to be displayed is not in the message table but simply hard-coded in the application procedure, then as noted in the argument description, the first argument is replaced by a question mark to signal this, and the second argument is the message text. An example use of an include file for a hard-coded message with no insertion codes is:
This example shows a Progress Dynamics message with two insertion codes and the table/field names specified:
This example uses a Progress Dynamics message with two insertion codes and no table/field specified:
Since
aferrortxt.iactually evaluates to the formatted message, you must place it into a context where that message will be returned appropriately. An example in an application is:
Or, as used in the procedures that come out of the Object Generator (and as you should normally also code such procedures), potentially multiple messages are accumulated in a single string using this convention:
You should take advantage of the message table wherever possible in your application. Using standard messages for errors and for any other message displays supports the translation and reuse of messages. Hard-coding a message in an application means that it cannot easily be translated. Any change to the message text requires a change to the source code of the application.
The insertion codes can be a valuable mechanism for enabling you to reuse essentially the same message in different circumstances. Do not overdo the substitutions, however. If what you are inserting is the name of a table, field, or value, or some other entity that does not require translation, then message reuse is maximized. However, if you put text that really requires translation into the insertion parameter, such as
“Error - &1”, then you would be defeating the purpose of the message table, which is to put the meaningful text in one place where it can be maintained, customized where necessary, and translated.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |